// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-6-21

#ifndef __CTRL_H_COMMON_UI__
#define __CTRL_H_COMMON_UI__

#pragma once

#include "manager.h"


//##ModelId=44CF17B801F6
enum AlignType
{
	//##ModelId=44CF17B801F8
    AT_None,
	//##ModelId=44CF17B80203
    AT_Left,
	//##ModelId=44CF17B80204
    AT_Top,
	//##ModelId=44CF17B80205
    AT_Right,
	//##ModelId=44CF17B80206
    AT_Bottom,
	//##ModelId=44CF17B80213
    AT_Client,
};

//##ModelId=44CF17B80214
enum MouseMessage
{
	//##ModelId=44CF17B80222
    MM_Move,
    //MM_Hover,
    //MM_Leave,
	//##ModelId=44CF17B80223
    MM_LeftDown,
	//##ModelId=44CF17B80224
    MM_LeftUp,
	//##ModelId=44CF17B80225
    MM_LeftDouble,
	//##ModelId=44CF17B80232
    MM_RightDown,
	//##ModelId=44CF17B80233
    MM_RightUp,
	//##ModelId=44CF17B80234
    MM_RightDouble,
	//##ModelId=44CF17B80235
    MM_Wheel,
};

class CJoyWnd;

inline Rect ConvertRect(const CRect& r)
{
    return Rect(r.left, r.top, r.Width(), r.Height());
}
inline CRect ConvertRect(const Rect& r)
{
    return CRect(r.X, r.Y, r.GetRight(), r.GetBottom());
}

//##ModelId=44CF17B80280
class CJoyCtrl
{
protected:

    friend class CJoyWnd;

	//##ModelId=44CF17B80281
    bool    m_visible;
	//##ModelId=44CF17B80282
    bool    m_enabled;
	//##ModelId=44CF17B80283
    bool    m_active;
	//##ModelId=44CF17B80290
    bool    m_canActive;

	//##ModelId=44CF17B80294
    CJoyCtrl*   m_parent;
	//##ModelId=44CF17B80297
    AlignType   m_align;
	//##ModelId=44CF17B8029F
    CRect       m_area;
	//##ModelId=44CF17B802A1
    Region*     m_clip;
	//##ModelId=44CF17B802AF
    CPoint      m_leftDown;
	//##ModelId=44CF17B802B0
    DWORD       m_lastLeftDown;
	//##ModelId=44CF17B802B1
    DWORD       m_doubleDelay;

	//##ModelId=44CF17B802C2
    CList<CJoyCtrl*>    m_childs;

	//##ModelId=44CF17B802C4
    POSITION GetChildPos(CJoyCtrl* child);
	//##ModelId=44CF17B802C6
    virtual void DoAlignChilds(CRect& remain);
	//##ModelId=44CF17B802D0
    virtual bool PointIn(const CPoint& p);
	//##ModelId=44CF17B802DF
    void AddChild(CJoyCtrl* child);
	//##ModelId=44CF17B802EE
    void RemoveChild(CJoyCtrl* child);

	//##ModelId=44CF17B802FD
    void CJoyCtrl::DoAlignChilds()
    {
        CRect remain(0, 0, m_area.Width(), m_area.Height());
        DoAlignChilds(remain);
    }
	//##ModelId=44CF17B802FE
    CJoyCtrl* FindCtrl(const CPoint& pt, bool (*pfnIsValid)(CJoyCtrl*));


    // control messages.

	//##ModelId=44CF17B8030D
    virtual LRESULT CM_HitTest(const CPoint& pt);
	//##ModelId=44CF17B80310
    virtual void CM_MouseLeave();
	//##ModelId=44CF17B80312
    virtual void CM_MouseHover();
	//##ModelId=44CF17B8031D
    virtual void CM_Mouse(MouseMessage msg, const CPoint& pt);
	//##ModelId=44CF17B80321
    virtual void CM_ParentEnabled(bool enabled);
	//##ModelId=44CF17B8032E
    virtual void CM_Enabled(bool e);
	//##ModelId=44CF17B80331
    virtual void CM_Visible(bool v);
	//##ModelId=44CF17B8033C
    virtual void CM_Sizing(UINT edge, CRect& area);
	//##ModelId=44CF17B80340
    virtual void CM_Size(const CSize& s);
	//##ModelId=44CF17B8034B
    virtual void CM_Move(const CPoint& p);
	//##ModelId=44CF17B8034E
    virtual void CM_Drag(const CPoint& p);
	//##ModelId=44CF17B8035B
    virtual void CM_LoadSkin(CJoyXmlElement* pSkinElem);
	//##ModelId=44CF17B8035E
    virtual bool CM_Create();
	//##ModelId=44CF17B80360
    virtual void CM_Destroy();
	//##ModelId=44CF17B80362
    virtual void CM_NotifyAlign();
	//##ModelId=44CF17B8036C
    virtual void CM_Draw(Graphics& graph);
	//##ModelId=44CF17B8036F
    virtual void CM_Clip(Graphics& graph);
	//##ModelId=44CF17B8037A
    virtual void CM_Active(bool active);

public:
	//##ModelId=44CF17B8037D
    CString     m_name;
	//##ModelId=44CF17B8037E
    LRESULT     m_hitTest;
	//##ModelId=44CF17B8038A
    CRect       m_moveArea;
	//##ModelId=44CF17B8038B
    bool        m_skinArea;
	//##ModelId=44CF17B8038C
    bool        m_skinAlign;
	//##ModelId=44CF17B8038D
    bool    m_hitTrans;
	//##ModelId=44CF17B80399
    bool    m_recvMouse;

	//##ModelId=44CF17B8039B
    CStringW    m_textFace;
	//##ModelId=44CF17B8039F
    int         m_textSize;
	//##ModelId=44CF17B803AA
    Color       m_textColor;
	//##ModelId=44CF17B803AF
    Color       m_backColor;



public:
	//##ModelId=44CF17B803B3
    CJoyCtrl(void);
	//##ModelId=44CF17B803BA
    virtual ~CJoyCtrl(void);

	//##ModelId=44CF17B803C8
    void InvalidateCtrl()
    {
        InvalidateCtrl(CRect(0, 0, m_area.Width(), m_area.Height()));
    }
	//##ModelId=44CF17B803C9
    bool IsVisible() const
    {
        return m_visible;
    }
	//##ModelId=44CF17B803CB
    bool IsEnabled() const
    {
        return m_enabled;
    }
	//##ModelId=44CF17B803CD
    virtual void SetVisible(bool v);
	//##ModelId=44CF17B803D8
    bool CanRecvMouse() const
    {
        return m_recvMouse;
    }
	//##ModelId=44CF17B803DA
    void SetClip(Region* clip);
	//##ModelId=44CF17B90000
    void SetBackColor(Color backColor);
	//##ModelId=44CF17B9000F
    void FillBack(Graphics& graph, Color c);
	//##ModelId=44CF17B90012
    Color GetBackColor() const
    {
        return m_backColor;
    }
	//##ModelId=44CF17B90014
    AlignType GetAlign() const
    {
        return m_align;
    }
	//##ModelId=44CF17B90016
    const CRect& GetArea() const
    {
        return m_area;
    }
	//##ModelId=44CF17B90020
    void SetCtrlCapture()
    {
        SetCtrlCapture(this);
    }
	//##ModelId=44CF17B90021
    void ReleaseCtrlCapture()
    {
        ReleaseCtrlCapture(this);
    }

	//##ModelId=44CF17B90022
    virtual bool IsWnd();
	//##ModelId=44CF17B90024
    virtual bool Create(CJoyCtrl* parent, const CRect& area);
	//##ModelId=44CF17B9002E
    virtual void Destroy();
	//##ModelId=44CF17B9003E
    virtual void Draw(Graphics& graph);
	//##ModelId=44CF17B90041
    virtual void AlignChilds();
	//##ModelId=44CF17B9004E
    virtual void SetArea(const CRect& area);
	//##ModelId=44CF17B90051
    virtual void InvalidateCtrl(const CRect& area);
	//##ModelId=44CF17B9005D
    virtual void CtrlToWnd(CPoint& pt);
	//##ModelId=44CF17B90060
    virtual void CtrlToScreen(CPoint& pt);
	//##ModelId=44CF17B9006D
    virtual void SetAlign(AlignType align);
	//##ModelId=44CF17B90070
    virtual void NotifyAlign();
	//##ModelId=44CF17B90072
    virtual void LoadSkin(CJoyXmlElement* skinXml);
	//##ModelId=44CF17B9007D
    virtual void SetCtrlCapture(CJoyCtrl* pCtrl);
	//##ModelId=44CF17B9008C
    virtual void ReleaseCtrlCapture(CJoyCtrl* pCtrl);
	//##ModelId=44CF17B9008F
    virtual void SetEnabled(bool e);
};

#endif  // __CTRL_H_COMMON_UI__
